package com.ruoyi.quartz.task;

import com.ruoyi.mk.domain.MkZdgl;
import com.ruoyi.mk.domain.MkZdrz;
import com.ruoyi.mk.service.IMkZdglService;
import com.ruoyi.mk.service.IMkZdrzService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Component("rzTask")
public class RzTask {

    @Autowired
    private IMkZdglService iMkZdglService;

    @Autowired
    private IMkZdrzService iMkZdrzService;

    public void rzInsert() {
        MkZdgl mkZdgl = new MkZdgl();
        //查询终端管理信息
        List<MkZdgl> zdglList = iMkZdglService.selectMkZdglList(mkZdgl);

        //终端编号
        List<Long> idList = zdglList.stream().map(MkZdgl::getId).collect(Collectors.toList());

        //报警状态
        List<Long> baoJingList = zdglList.stream().map(MkZdgl::getZdBaojing).collect(Collectors.toList());

        //信号强度
        List<Long> qiangDuList = zdglList.stream().map(MkZdgl::getZdQiangdu).collect(Collectors.toList());

        //剩余电量
        List<Long> dianLiangList = zdglList.stream().map(MkZdgl::getZdDianliang).collect(Collectors.toList());

        //当前数据
        List<String> shuJuList = zdglList.stream().map(MkZdgl::getZdShuju).collect(Collectors.toList());

        //报警详情
        List<String> xiangJinList = zdglList.stream().map(MkZdgl::getZdXiangjin).collect(Collectors.toList());

        //定义对象数组
        MkZdrz[] mkZdrzs = new MkZdrz[idList.size()];

        //创建时间
        Date date = new Date();

        //循环为对象数组赋值
        for (int i = 0; i < idList.size(); i++) {
            mkZdrzs[i] = new MkZdrz(
                    0l,//id
                    idList.get(i),//终端编号
                    0l,//帧数计时器
                    baoJingList.get(i),//报警类型
                    qiangDuList.get(i),//信号强度
                    dianLiangList.get(i),//剩余电量
                    shuJuList.get(i),//当前数据
                    xiangJinList.get(i),//报警详情
                    date,
                    0l
            );

            //将对象数据进行保存
            iMkZdrzService.insertMkZdrz(mkZdrzs[i]);
        }


//        System.out.println(zdglList);
        System.out.println("定时添加");
    }



    public void rzDelete() {

        List<MkZdrz> zdrzList =iMkZdrzService.selectMkZdrzBeforeFifteen();
        List<Long> idList = zdrzList.stream().map(MkZdrz::getRzId).collect(Collectors.toList());
        Long[] array1 =idList.toArray(new Long[idList.size()]);

        //  不要轻易调动（真删除）！！！！！！！！！！！！！！！！！！！！
        //iMkZdrzService.deleteMkZdrzByRzIds(array1);

         System.out.println("定时删除");

    }

}
